package com.walnut.lom_system.controller;

import com.walnut.lom_system.common.lang.ResultInfo;
import com.walnut.lom_system.common.util.ResultInfoUtil;
import com.walnut.lom_system.domain.entity.UserInfo;
import com.walnut.lom_system.domain.form.UserInfoForm;
import com.walnut.lom_system.domain.vo.UserInfoVo;
import com.walnut.lom_system.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author chenhetao
 * @version 1.0
 * @className SysUserController
 * @description TODO
 * @date 2022/4/5 21:36
 */
@Controller
@RequestMapping("/sys/user")
@Api(tags = "系统级用户管理")
public class SysUserController {

    @Autowired
    UserInfoService userInfoService;

    @ApiOperation("获取单个用户信息")
    @GetMapping()
    public ResultInfo<UserInfoVo> getUser(@RequestBody @Validated UserInfoForm userInfoForm){
        //TODO
        UserInfoVo user = userInfoService.getUser(userInfoForm);
        System.out.println(user);
        return ResultInfoUtil.buildSuccess(user);
    }

    @ApiOperation("获取指定页用户信息")
    @GetMapping("/list")
    public ResultInfo<List<UserInfo>> getUserList(){
        //TODO
        return null;
    }



    @ApiOperation("批量删除用户信息")
    @DeleteMapping("/list")
    public ResultInfo<List<UserInfo>> deleteUserList(){
        //TODO
        return null;
    }

    @ApiOperation("新增用户信息")
    @PostMapping()
    public ResultInfo<List<UserInfo>> addUser(){
        //TODO
        return null;
    }

    @ApiOperation("通过excel导入两委用户名单")
    @PostMapping("/import")
    public ResultInfo<String> importUser(MultipartFile multipartFile){
        return userInfoService.importUserInfo(multipartFile)? ResultInfoUtil.buildSuccess("导入成功"):ResultInfoUtil.buildError("导入失败");
    }

}
